import os
from fnmatch import fnmatch
import glob

# 想获取文件系统中某个目录下的所有文件列表,匹配文件名
def demo_1():
    names = [name for name in os.listdir('../temp') if os.path.isfile(os.path.join('../temp', name))]
    print(names)

# startswith()与endswith()函数进行名称过滤
def demo_2():
    py_files = [name for name in os.listdir('../temp') if name.endswith('.py')]
    s_files = [name for name in os.listdir('../temp') if name.startswith('s')]
    print(py_files)
    print(s_files)
    py_files_fnmatch = [name for name in os.listdir('../temp') if fnmatch(name, '*.py')]
    print(py_files_fnmatch)

# 匹配文件名称与元信息
def demo_3():
    pyfiles = glob.glob('*.py')
    name_sz_date = [(name, os.path.getsize(name), os.path.getmtime(name)) for name in pyfiles]
    for name, size, mtime in name_sz_date:
        print(name, size, mtime)

if __name__ == '__main__':
    # demo_1()
    # demo_2()
    demo_3()